/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mopso;

/**
 *
 * @author robson
 */
public class Particle_CSS implements Comparable, Cloneable {

    private ParticleData particleData;
    private boolean dominated;
    private Particle_CSS gBest1;
    private Particle_CSS gBest2;    
    private Problem problem;

    public Particle_CSS(Problem problem) {
        this.problem = problem;
        particleData = new ParticleData(problem);
    }

    public Particle_CSS(Problem problem, int index) {
        this.problem = problem;
        particleData = new ParticleData(problem, index);
    }

    public void calculateFitness() {
        for (int i = 0; i < problem.getFunctions().size(); i++) {
            particleData.getFitness()[i] = problem.getFunctions().get(i).function(getParticleData().getPositions());
        }

        particleData.setGValue(problem.getGValue());
    }

    public ParticleData getParticleData() {
        return particleData;
    }

    public void setParticleData(ParticleData particleData) {
        this.particleData = particleData;
    }

    public boolean isDominated() {
        return dominated;
    }

    public void setDominated(boolean dominated) {
        this.dominated = dominated;
    }

    public Object clone() {
        Particle_CSS clone = new Particle_CSS(problem);
        
//        if( gBest1 != null ) {
//            clone.gBest1 = (Particle_CSS) this.gBest1.clone();    
//        }
//        
//        if( gBest2 != null) {
//            clone.gBest2 = (Particle_CSS) this.gBest2.clone();        
//        }        
        
        clone.dominated = this.dominated;
        clone.particleData = (ParticleData) this.particleData.clone();

        return clone;
    }

    public int compareTo(Object obj) {
        return this.particleData.compareTo(((Particle_CSS) obj).particleData);
    }

    public Particle_CSS getGBest1() {
        return gBest1;
    }

    public void setGBest1(Particle_CSS gBest1) {
        this.gBest1 = gBest1;
    }

    public Particle_CSS getGBest2() {
        return gBest2;
    }

    public void setGBest2(Particle_CSS gBest2) {
        this.gBest2 = gBest2;
    }
}
